<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
    <meta name="author" content="火星科技 http://mars3d.cn " />
    <meta name="apple-touch-fullscreen" content="yes" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="x5-fullscreen" content="true" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
    <!-- 标题及搜索关键字 -->
    <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
    <meta
      name="description"
      content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型  gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包  地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS"
    />

    <link rel="shortcut icon" type="image/x-icon" href="http://mars3d.cn/favicon.ico" />
    <title>GeoServer矢量服务查询(OGC WFS) | Mars3D | 三维地图 | 火星科技 | 合肥火星科技有限公司</title>

    <!--第三方lib-->
    <script
      type="text/javascript"
      src="../lib/include-lib.js"
      libpath="../lib/"
      include="jquery,font-awesome,web-icons,bootstrap,bootstrap-table,bootstrap-checkbox,layer,toastr,haoutil,turf,mars3d"
    ></script>

    <link href="css/style.css" rel="stylesheet" />
  </head>

  <body class="dark">
    <!--加载前进行操作提示，优化用户体验-->
    <div id="mask" class="signmask" onclick="removeMask()"></div>

    <div id="mars3dContainer" class="mars3d-container"></div>

    <div class="infoview">
      <table class="mars-table">
        <tr>
          <td class="nametd">名称：</td>
          <td>
            <input id="queryText" type="text" placeholder="请输入查询关键字" value="" class="form-control" />
          </td>
        </tr>
        <tr>
          <td class="nametd">范围：</td>
          <td>
            <input type="button" class="btn btn-primary" value="框选范围" id="drawRectangle" />
            <input type="button" class="btn btn-primary" value="圆形范围" id="drawCircle" />
            <input type="button" class="btn btn-primary" value="多边形范围" id="drawPolygon" />
          </td>
        </tr>
        <tr>
          <td class="nametd">范围：</td>
          <td>
            <input type="button" class="btn btn-primary" value="查询" id="query" />
            <input type="button" class="btn btn-primary" value="清除" id="removeAll" />
          </td>
        </tr>
      </table>

      <div id="resultView" style="max-width: 500px; display: none">
        <table id="table" style="table-layout: fixed; word-break: break-all"></table>
      </div>
    </div>

    <script src="./js/common.js"></script>
    <script type="text/javascript">
      "use script"; //开发环境建议开启严格模式

      var map;
      var queryMapserver;
      var geoJsonLayer;

      var drawGraphic;
      var $table;

      function initMap(options) {
        //合并属性参数，可覆盖config.json中的对应配置
        var mapOptions = mars3d.Util.merge(options, {
          scene: {
            center: { lat: 31.79536, lng: 117.255222, alt: 16294, heading: 358, pitch: -76 },
          },
        });

        //创建三维地球场景
        map = new mars3d.Map("mars3dContainer", mapOptions);

        queryMapserver = new mars3d.query.QueryGeoServer({
          url: "//server.mars3d.cn/geoserver/mars/wfs",
          layer: "mars:hfjy",
          maxFeatures: 200,
        });

        //用于显示查询结果（geojson）的图层
        geoJsonLayer = new mars3d.layer.GeoJsonLayer({
          symbol: {
            styleOptions: {
              image: "img/marker/mark3.png",
              scale: 1,
              scaleByDistance: true,
              scaleByDistance_far: 20000,
              scaleByDistance_farValue: 0.5,
              scaleByDistance_near: 1000,
              scaleByDistance_nearValue: 1,
              clampToGround: true,
              label: {
                text: "{项目名称}",
                font_size: 25,
                color: "#ffffff",
                outline: true,
                outlineColor: "#000000",
                pixelOffsetY: -25,
                scaleByDistance: true,
                scaleByDistance_far: 80000,
                scaleByDistance_farValue: 0.5,
                scaleByDistance_near: 1000,
                scaleByDistance_nearValue: 1,
                distanceDisplayCondition: true,
                distanceDisplayCondition_far: 80000,
                distanceDisplayCondition_near: 0,
              },
            },
          },
          popup: "all",
        });
        map.addLayer(geoJsonLayer);

        geoJsonLayer.on(mars3d.EventType.load, geoJsonLayer_onLoadHandler);

        //框选查询   多边
        $("#drawPolygon").click(function () {
          clearAll();
          map.graphicLayer.startDraw({
            type: "polygon",
            style: {
              color: "#00FF00",
              opacity: 0.3,
              outline: true,
              outlineColor: "#ffffff",
              clampToGround: true,
            },
            success: function (graphic) {
              drawGraphic = graphic;
            },
          });
        });

        //框选查询 矩形
        $("#drawRectangle").click(function () {
          clearAll();
          map.graphicLayer.startDraw({
            type: "rectangle",
            style: {
              color: "#00FF00",
              opacity: 0.3,
              outline: true,
              outlineColor: "#ffffff",
              clampToGround: true,
            },
            success: function (graphic) {
              drawGraphic = graphic;
            },
          });
        });

        //框选查询   圆
        $("#drawCircle").click(function () {
          clearAll();
          map.graphicLayer.startDraw({
            type: "circle",
            style: {
              color: "#00FF00",
              opacity: 0.3,
              outline: true,
              outlineColor: "#ffffff",
              clampToGround: true,
            },
            success: function (graphic) {
              drawGraphic = graphic;
            },
          });
        });

        $("#removeAll").click(function () {
          clearAll();
        });
        $("#query").click(function () {
          queryData();
        });

        $table = $("#table");
        $table.bootstrapTable({
          singleSelect: true, //单选
          iconsPrefix: "fa",
          pagination: true,
          showPaginationSwitch: false,
          pageNumber: 1,
          pageSize: 5,
          pageList: [5, 10, 20, 50, 100],
          columns: [
            {
              title: "", //序号
              sortable: false,
              align: "center",
              width: 50,
              formatter: function (value, row, index) {
                return index + 1;
              },
            },
            {
              field: "项目名称",
              title: "名称",
              sortable: true,
              width: 100,
            },
            {
              field: "设施类型",
              title: "类型",
              sortable: true,
              align: "center",
              width: 70,
            },
            {
              field: "具体位置",
              title: "地址",
              sortable: true,
              formatter: function (value, row) {
                if (value) {
                  return value;
                } else {
                  return "";
                }
              },
            },
          ],
          onClickRow: function (item, $element, field) {
            var graphic = item.graphic;
            if (graphic == null) {
              toastr.warning(item.name + " 无经纬度坐标信息！");
              return;
            }
            graphic.flyTo({ radius: 1000 });
          },
        });
      }

      function clearAll(noClearDraw) {
        $("#resultView").hide();

        drawGraphic = null;
        map.graphicLayer.clear();
        geoJsonLayer.clear();
      }

      function queryData() {
        $("#resultView").hide();

        var queryVal = $.trim($("#queryText").val());

        queryMapserver.query({
          column: "项目名称",
          text: queryVal,
          graphic: drawGraphic,
          success: (result) => {
            if (result.count == 0) {
              haoutil.msg("未查询到相关记录！");
              return;
            } else {
              haoutil.msg("共查询到 " + result.count + " 条记录！");
            }
            geoJsonLayer.load({ data: result.geojson });
          },
          error: (error, msg) => {
            console.log("服务访问错误", error);
            haoutil.alert(msg, "服务访问错误");
          },
        });
      }

      function geoJsonLayer_onLoadHandler(event) {
        $table.bootstrapTable("load", event.list);
        $("#resultView").show();
      }
    </script>
  </body>
</html>
